/**
 * Copyright (c) 2011 ~ 2014 Deepin, Inc.
 *               2013 ~ 2014 jouyouyun
 *
 * Author:      jouyouyun <jouyouwen717@gmail.com>
 * Maintainer:  jouyouyun <jouyouwen717@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

package main

import (
	"fmt"
	"reflect"
	"time"
)

var (
	termInfo = []int32{0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758}
)

func getDay(year, n int32) {
	off := time.Date(1890, 0, 5, 0, 0, 0, 0, time.UTC).Unix()
	fmt.Printf("1890 offset: %v\n", off)
	offset := int64(31556925974/1000*(year-1971)+termInfo[n]*42445) - off
	fmt.Printf("offset: %v\n", offset)
	y, m, d := time.Unix(offset, 0).Date()
	fmt.Printf("Date: %v - %v - %v\n", y, m, d)

	fmt.Println("*** offset: ", time.Date(2014, 2, 4, 0, 0, 0, 0, time.UTC).Unix())
}

func main() {
	t := time.Now()
	y, m, d := t.Date()
	fmt.Printf("Date: %v - %v - %v\n\tTimestamp: %v\n",
		y, m, d, t.Unix())
	ts := t.Unix() + 1*86400
	t1 := time.Unix(ts, 0)
	y1, m1, d1 := t1.Date()
	fmt.Printf("Date: %v - %v - %v\n\tTimestamp: %v\n",
		y1, m1, d1, t1.Unix())

	//t2 := time.Unix(31556925974/1000, 0)
	t2 := time.Unix(31556926, 0)
	y2, m2, d2 := t2.Date()
	fmt.Printf("Date: %v - %v - %v\n", y2, m2, d2)
	fmt.Printf("Month type: %v\n", reflect.TypeOf(m2).Name())

	getDay(2014, 2)
	getDay(2013, 2)
}
